<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="renderer" content="webkit">
  <link href="../css/bootstrap.min.css" rel="stylesheet">
  <link href="../css/font-awesome.min.css" rel="stylesheet">
  <link href="../css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
  <link href="../css/animate.css" rel="stylesheet">
  <link href="../css/style.css" rel="stylesheet">
  <link href="../css/plugins/toastr/toastr.min.css" rel="stylesheet">
</head>
<body>

  <div class="row border-bottom">
				<nav class="navbar navbar-static-top" data-role="navigation">
					<div class="navbar-header">
						<div class="minimalize-styl-2">
							<a class="btn btn-success" title="返回主页" href="../main.html"><i class="fa fa-lg fa-home"></i></a>
							<a class="back-link btn btn-success" title="后退"><i class="fa fa-lg fa-arrow-left"></i></a>
							<a class="reload-link btn btn-success" title="重新加载"><i class="fa fa-lg fa-repeat"></i></a>
<!-- ++++++++++++++++++++++++++++++++ -->
<ol id="guide" class="breadcrumb m-l">
	<li><strong>领货</strong></li>
</ol>
<!-- ################################ -->
						</div>
					</div>
					<div class="nav navbar-top-links navbar-right minimalize-styl-2">
						<span class="m-r-sm text-muted welcome-message btn btn-link">欢迎使用Feces物流管理系统</span>
					</div>
				</nav>
			</div>
  <div class="gray-bg dashbard-1">
    <div class="wrapper wrapper-content animated fadeInRight">
      <div class="row">
        <div class="col-lg-12">
          <div class="ibox float-e-margins">
            <div class="ibox-title">
              <h5>分站仓库领货</h5>
            </div>
            <div class="ibox-content">
              <form>
              <table class="table table-striped table-bordered table-hover "
                id="editable">
                <thead>
                  <tr>
                    <th>选择</th>
                    <th>调拨单号</th>
                    <th>商品代码</th>
                    <th>商品名称</th>
                    <th>计量单位</th>
                    <th>数量</th>
                    <th>任务号</th>
                    <th>日期</th>
                  </tr>
                </thead>
                <tbody>
                  <tr class="gradeA">
                    <td><input type="checkbox"></td>
                    <td>预留</td>
                    <td>预留</td>
                    <td>预留</td>
                    <td>预留</td>
                    <td>预留</td>
                    <td>预留</td>
                    <td>预留</td>
                  </tr>
                </tbody>
              </table>
              <div class="">
                <a onclick="fnClickAddRow();" href="javascript:void(0);"
                  class="btn btn-primary ">领货</a>
              </div>
            </form>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <script src="../js/jquery-2.1.1.min.js"></script>
  <script src="../js/bootstrap.min.js"></script>
  <script src="../js/plugins/metisMenu/jquery.metisMenu.js"></script>
  <script src="../js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
  <script src="../js/plugins/jeditable/jquery.jeditable.js"></script>
  <script src="../js/plugins/dataTables/jquery.dataTables.js"></script>
  <script src="../js/plugins/dataTables/dataTables.bootstrap.js"></script>
  <script src="../js/plugins/pace/pace.min.js"></script>
  <script src="../js/plugins/toastr/toastr.min.js"></script>
  <script src="../js/feces.js"></script>
<script type="text/javascript">
  var url="../api/allocation?time="+new Date().getTime();
  var data;
  var msg = [];
  $(document).ready(function(){
    $('#editable').dataTable({
      ajax: {
        type:"GET",
        url: url,
        // 处理数据
        dataSrc: function(R){
          // 将返回的Hash类型数据修改为Array
          var a = [];
          data = R.data;
          for (var i = 0; i < data.length; ++i) {
            var datum = data[i];
            var flag = datum.taskVoucher.task_state=="已分配" ? true : false;
            if(flag){
              for (var j = 0; j < datum.clientOrder.products.length; ++j) {
                var product = datum.clientOrder.products[j];
                //     console.log(product);
                a.push([j, datum.id, product.product.id, product.product.name, product.product.unit, product.product_number, datum.taskVoucher.task_number, datum.out_date])
              }
            }
          }
          return a;
        }
      },
      stateSave: true,
      createdRow: function(row, data, dataIndex){
        if (data[0] == 0) {
          $("td:eq(0)", row).html('<input type="checkbox" id="check" name="check"></input>')
        } else {
          $("td:eq(0)", row).empty()
        }
      }
    });
  });
  function fnClickAddRow(){
    $('#editable').find('tr').each(function(){
      if($(this).children().eq(0).find("input:checkbox").prop("checked")){
        var z=$(this).children().eq(1).text();
        msg.push(z);
      }
    });
    var s1 = "picking";
    $.ajax({
      type:"PUT",
      url:url,
      data:{
        "operation" : s1 ,
        "ids" : JSON.stringify(msg)
      },
      success:function(){
        location.reload();
      }
    });
  }

</script>

</body>

</html>
